#pragma once

#include <ECS/ECS.h>
#include <ECS/Math/Vec2.h>
#include <ECS/Patterns/Nullable.h>
#include "Actuator.h"
#include "../Transform.h"
#include "../Pathfinding/TileData.h"

struct VehicleDef : public ActuatorDef
{
	mtMETA_DEC;
};

class Vehicle : public Actuator
{
	mtMETA_DEC;
public:
	bool initWith(VehicleDef* def);

	void setTarget(const ECS::Vec2<float>& point);
	bool hasTarget() const;
	void clearTarget();

	void onStart();
	void onUpdate();
protected:
	float _speed;
	Transform* _cachedTransform;
	MapData* _map;
	ECS::Nullable<ECS::Vec2<float> > _target;
	
	typedef std::vector< ECS::Vec2<int> > Route;
	Route _route;

	bool doMoveTo(const ECS::Vec2<float>& _wayPoint, float& length);

	bool findPath(const ECS::Vec2<int>& start, const ECS::Vec2<int>& target, Route* path);
};
